package opearaion;

import book.Book;
import book.BookList;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LXW
 * Date: 2021-12-09
 * Time: 12:13
 */
public class AddOperation implements IOperation{
    @Override
    public void work(BookList booklist) {
        System.out.println("新增图书");
        System.out.println("请输入图书的名字");
        String name = scanner.nextLine();
        System.out.println("请输入图书的作者");
        String author = scanner.nextLine();
        System.out.println("请输入图书的价格");
        int price = scanner.nextInt();
        System.out.println("请输入图书的类型");
        String type = scanner.nextLine();

        Book book = new Book(name,author,price,type);   // new一个要添加的书
        int size = booklist.getSize();        // 获得目前图书的数量
        booklist.setPos(size,book);      // 在现有图书数量的最后一个位置添加这本书
        booklist.setSize(size+1);        // 图书数量加1
        System.out.println("新增图书成功!");
    }
}
